@namespace MduiBlazor
@inherits MduiComponentBase
@typeparam TValue

@if (HasChildren)
{
    <MduiCollapse Open="@_opened">
        <HeaderContent>
            <div class="mdui-treeview-item">
                <MduiIconButton Class="mdui-collapse-arrow" Icon="keyboard_arrow_down" OnClick="@(_=>_opened=!_opened)"
                    DisableRipple="@Root.DisableRipple" />
                <label class="@TitleClassname" @onclick="@OnClickItemAsync" @onclick:stopPropagation="@true">
                    @if (Root.MultiSelection)
                    {
                        <MduiCheckbox Value="@Checked" ValueChanged="@OnCheckedChanged" />
                    }
                    @if (TitleContent is not null)
                    {
                        @TitleContent
                    }
                    else
                    {
                        @Title
                    }
                </label>
            </div>
        </HeaderContent>
        <ChildContent>
            <CascadingValue Value="@this" IsFixed>
                <ul class="mdui-treeview" style="padding-left:@Root.Indent">
                    @ChildContent
                </ul>
            </CascadingValue>
        </ChildContent>
    </MduiCollapse>
}
else
{
    <li class="mdui-treeview-item">
        <label class="@TitleClassname" @onclick="@OnClickItemAsync" @onclick:stopPropagation="@true">
            @if (Root.MultiSelection)
            {
                <MduiCheckbox Value="@Checked" ValueChanged="@OnCheckedChanged" />
            }
            @if (TitleContent is not null)
            {
                @TitleContent
            }
            else
            {
                @Title
            }
        </label>
    </li>
}